package com.yowasa.xiuxian.engine.battle.strategy.skill.gold;

import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.CalAbility;
import com.yowasa.xiuxian.engine.battle.strategy.InherentStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.InherentTiming;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@BS(name = "御剑术",upAbility = 4,needTravel = 1000)
@Order(-1001)
@Component
public class YuJianShu extends CalAbility implements InherentStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return ElementEnum.GOLD;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int atk = first.getBattleInfo().getAtk();
        int def = second.getBattleInfo().getDef();
        int dmg = (int) (battleHelper.calAtk(atk, def) * 0.7);
        battleHelper.autoAction(this, first, second, content, dmg, "御剑术");
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("金") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用御剑术必须具有金灵根");
        }
        if (user.getStage() < StageEnum.ZHU_JI.getLevel()) {
            throw new HandlerException("学习/使用御剑术至少要始明之青");
        }
    }
    @Override
    public String limitDesc() {
        return "达到始明之青且具有金灵根";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        if (RandomUtil.randomInt(10) < 5) {
            return false;
        }
        //校验蓝
        if (user.getBattleInfo().getCmp() < 10) {
            return false;
        }
        return true;
    }

    @Override
    public List<InherentTiming> getTiming() {
        return Lists.newArrayList(InherentTiming.SELF_BEGIN, InherentTiming.SELF_END);
    }

    @Override
    public String desc() {
        return "自己回合开始和结束时各有50%的概率消耗10点MP对对手造成基于自己物理攻击力70%的物理伤害";
    }
}
